package com.gimc.evil.config

import org.springframework.boot.autoconfigure.AutoConfigureAfter
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
import org.springframework.context.annotation.{Bean, Configuration}
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.data.redis.serializer.{GenericJackson2JsonRedisSerializer, StringRedisSerializer}

/**
 *
 * @author yin.he
 */
@Configuration
@AutoConfigureAfter(Array(classOf[RedisAutoConfiguration]))
class RedisConfig {

  @Bean
  def redisCacheTemplate(redisConnectionFactory: LettuceConnectionFactory): RedisTemplate[String, Object] = {
    val template: RedisTemplate[String, Object] = new RedisTemplate()
    template.setKeySerializer(new StringRedisSerializer())
    template.setValueSerializer(new GenericJackson2JsonRedisSerializer())
    template.setConnectionFactory(redisConnectionFactory)
    template
  }
}